from Crypto.Cipher import AES
import base64


def encrypt(text):
    key = '1234567890123456'
    aes = AES.new(key.encode('utf-8'), AES.MODE_ECB)
    text = text.encode('utf-8')
    text = text + (16 - len(text) % 16) * chr(16 - len(text) % 16).encode('utf-8')
    ciphertext = aes.encrypt(text)
    ciphertext = base64.b64encode(ciphertext).decode('utf-8')
    return ciphertext


def decrypt(ciphertext):
    key = '1234567890123456'
    aes = AES.new(key.encode('utf-8'), AES.MODE_ECB)
    text = base64.b64decode(ciphertext.encode('utf-8'))
    decrypted_text = aes.decrypt(text)
    result = decrypted_text.decode('utf-8').rstrip(chr(decrypted_text[-1]))
    return result
if __name__ == '__main__':
    print(encrypt('123456'))
    print(decrypt(encrypt('123456')))
